#/bin/bash

# 验证传入参数
if (($#==0)); then
	echo "Usage:   sh sudo_sethostname.sh <96.100>, ip will be 192.168.<96.100>"
	echo "Warning: must exec with root"
    exit 1
fi

# 设置变量
last_ip=$(echo $1 | awk -F'.' '{print $2}')
name=fs${last_ip}
setIP=192.168.${1}
OP="-o StrictHostKeyChecking=no"
SSHCMD="sshpass -p p@ssword ssh ${OP} root@${setIP} "

# 远程执行命令
eval ${SSHCMD} 'hostnamectl set-hostname ${name}'
eval ${SSHCMD} 'echo "127.0.0.1 localhost ${name}" >> /etc/hosts'
eval ${SSHCMD} 'systemctl restart NetworkManager'
#eval ${SSHCMD} 'systemctl disable orcafs-client'
